package com.yusheng.tr.multi.service.impl;
import com.yusheng.exceptions.ServiceException;
import com.yusheng.tr.common.core.model.dto.multi.StatementDto;
import com.yusheng.tr.common.core.model.dto.multi.StmtMngDto;
import com.yusheng.tr.common.core.model.vo.multi.*;
import com.yusheng.tr.common.core.page.PageParam;
import com.yusheng.tr.common.core.utils.SecurityUtils;
import com.yusheng.tr.common.core.utils.minio.MinioUtils;
import com.yusheng.tr.common.core.utils.minio.ObjectItem;
import com.yusheng.tr.multi.utils.*;
import com.yusheng.tr.common.core.model.vo.multi.KongVO.*;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spire.xls.Workbook;
import com.spire.xls.Worksheet;
import com.yusheng.tr.common.core.entity.multi.ModelMngEntity;
import com.yusheng.tr.common.core.entity.multi.StmtMngEntity;
import com.yusheng.tr.multi.mapper.ModelMngMapper;
import com.yusheng.tr.multi.mapper.StmtMngMapper;
import com.yusheng.tr.multi.service.IModelMngService;
import com.yusheng.tr.multi.service.IStmtMngService;
import com.yusheng.tr.common.core.model.vo.multi.KongVO.ProjectItem;
import com.yusheng.tr.common.core.model.vo.multi.SuiDetailVO.*;
import com.yusheng.tr.common.core.model.vo.multi.TubeVO.CoiledTubeExcel;
import com.yusheng.tr.common.core.model.vo.multi.productionLog.LogWorkExcel;
import com.yusheng.tr.common.core.model.vo.multi.productionLog.LogWorksheet;
import com.yusheng.tr.common.core.model.vo.multi.productionLog.ProjectDetails;
import com.yusheng.tr.common.core.model.vo.multi.TubeVO.TubingContent;
import com.yusheng.tr.common.core.model.vo.multi.TubeVO.WorkProjectVO;
import com.yusheng.tr.common.core.model.vo.multi.qiaoVO.*;
import com.yusheng.utils.ConverterFormatUtils;
import com.yusheng.utils.FilePathUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

/**
 * <p>
 * 结算单管理表 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-10-07
 */
@Service
@Slf4j
@SuppressWarnings("all")
public class StmtMngServiceImpl extends ServiceImpl<StmtMngMapper, StmtMngEntity> implements IStmtMngService {

    @Autowired
    private IModelMngService modelMngService;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private ModelMngMapper modelMngMapper;

    @Autowired
    private MinioUtils minioUtils;

    @Autowired
    private StmtMngMapper stmtMngMapper;
    @Autowired
    private ConverterFormatUtils converterUtils;

    private final static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    @Override
    public PageInfo<StmtMngEntity> pageList(PageParam<StmtMngDto> dto) {

        //查询模型id
        Set<String> ids = new HashSet<>();
        if (StringUtils.isNotEmpty(dto.getParam().getModelName())) {
            List<ModelMngEntity> list = modelMngService.list(new LambdaQueryWrapper<ModelMngEntity>().like(ModelMngEntity::getName, dto.getParam().getModelName()));
            if (CollectionUtils.isNotEmpty(list)) {
                ids = list.stream().map(ModelMngEntity::getId).collect(Collectors.toSet());
            }
        }
        Set<String> finalIds = ids;
        return PageHelper.startPage(dto.getPageNum(), dto.getPageSize()).doSelectPageInfo(() -> list(new LambdaQueryWrapper<StmtMngEntity>().like(StringUtils.isNotEmpty(dto.getParam().getOrderNum()), StmtMngEntity::getOrderNum, dto.getParam().getOrderNum()).in(!CollectionUtils.isEmpty(finalIds), StmtMngEntity::getModelId, finalIds).ge(StringUtils.isNotEmpty(dto.getParam().getStartTime()), StmtMngEntity::getCreateTime, dto.getParam().getStartTime()).le(StringUtils.isNotEmpty(dto.getParam().getEndTime()), StmtMngEntity::getCreateTime, dto.getParam().getEndTime()).orderByDesc(StmtMngEntity::getCreateTime).like(StringUtils.isNotEmpty(dto.getParam().getFormName()), StmtMngEntity::getStmtName, dto.getParam().getFormName())));
    }


    @Override
    public ObjectItem testExcel(String id) throws Exception {
        //结算单实体
        Testvo fillData = new Testvo();
        //项目名称vo
        List<TestListVo> voList = new ArrayList<>();

        // 获取结算单
        StmtMngEntity stmtMng = this.getById(id);
        String jsonStr = String.valueOf(JSON.parseObject(stmtMng.getStmtContent()));
        StmtContent stmtContent = JSON.parseObject(jsonStr, StmtContent.class);
        Map<String, Object> itemMap = JSON.parseObject(stmtContent.getProjectItem(), Map.class);


        //吊车集合vo
        DiaocheVo diaocheVo = new DiaocheVo();
        List<DiaocheVo> list = new ArrayList<>();
        diaocheVo.setDiaochechehao(stmtContent.getDiaocheNumber());
        diaocheVo.setVehicleNumber(stmtContent.getDiaocheTon());

        list.add(diaocheVo);
        fillData.setDoList(list);

        List<ModelMngEntity> modelMng = modelMngMapper.findParentId(stmtMng.getModelId());
        for (ModelMngEntity mng : modelMng) {
            //曲线条数，项目名称实体
            TestListVo listVo = new TestListVo();
            String[] split = mng.getName().split("&&");
            listVo.setProjectName(split[0]);
            common(voList, itemMap, listVo, mng, split);
        }
        // PDF输出路径
        String outputPath = FilePathUtils.getTemplatePath("\\templete\\", "结算单数据.pdf");
        String templatePath = FilePathUtils.getTemplatePath("\\templete\\", "结算单.xlsx");
        //获取工作簿对象（整个Excel文件）
        ExcelWriter workBook = EasyExcel.write(outputPath)
                //与模板进行关联
                .withTemplate(templatePath).build();
        WriteSheet sheet = EasyExcel.writerSheet().build();
        //创建需要被填充的数据
        fillData.setDiaochechehao(stmtContent.getDiaocheNumber());
        fillData.setCondition(stmtContent.getSm_jk_mng());
        fillData.setDepartName(stmtContent.getDepName());
        fillData.setAllName(stmtContent.getSm_model_mng());
        fillData.setXiaoTeam(stmtContent.getXiaodui());
        fillData.setCreateTime(stmtContent.getCurrentTime());
        fillData.setAreaName(stmtContent.getSm_area_mng());
        fillData.setTeamCode(stmtContent.getZuanjingduihao());
        fillData.setTeamNum(stmtContent.getJinghao());
        fillData.setWoekProject(stmtContent.getSm_project_mng());
        fillData.setDeepth(stmtContent.getJingshen());
        fillData.setKilo(stmtContent.getDanchengongli());
        fillData.setTeamType(stmtContent.getSm_jx_mng());
        fillData.setKilo(stmtContent.getDanchengongli());
        fillData.setAngle(stmtContent.getZuidajingxie());
        fillData.setRequirearrive(stmtContent.getRequireGoTime());
        fillData.setArriveTime(stmtContent.getGoTime());
        fillData.setRequireReach(stmtContent.getRequireArriveTime());
        fillData.setReachTime(stmtContent.getArriveTime());
        fillData.setStartTime(stmtContent.getWorkTime());
        fillData.setFinshTime(stmtContent.getFinishWorkTime());
        fillData.setLeaveTime(stmtContent.getLeaveTime());
        fillData.setRetureTime(stmtContent.getBackTime());
        fillData.setMriNum(stmtContent.getHeciNumber());
        fillData.setVehicleNumber(stmtContent.getDiaocheTon());
        fillData.setNumber(stmtContent.getCejingNumber());
        fillData.setDeliveryNumber(stmtContent.getSongyiqiNumber());
        fillData.setOutdoorTem(stmtContent.getHighTemperature());
        fillData.setMinTem(stmtContent.getLowerTemperature());
        fillData.setTime(stmtContent.getCWaitZTime());
        fillData.setTimeTwo(stmtContent.getZWaitCTime());
        fillData.setCon(stmtContent.getHsNongdu());
        fillData.setDeepthH(stmtContent.getShuipingDeep());
        fillData.setDeepthA(stmtContent.getADeep());
        fillData.setTool(stmtContent.getShipingjing());
        fillData.setPressure(stmtContent.getPressure());
        fillData.setDensity(stmtContent.getDensity());
        fillData.setViscosity(stmtContent.getViscosity());
        fillData.setDelivery(stmtContent.getSm_material_mng());
        fillData.setBorrowed(stmtContent.getJieyuan());
        fillData.setTemperature(stmtContent.getJingdiTemperature());
        fillData.setManagement(stmtContent.getDizhijiandu());
        fillData.setManager(stmtContent.getXiangmujingli());
        //小队长：数组转为字符串
        String[] team = stmtContent.getCaptain();
        String captain = "";
        if (team != null && team.length > 0) {
            captain = String.join(",", team);
        }
        fillData.setLeader(captain);
        //操作工程师：数组转为字符串
        String[] operator = stmtContent.getEngineer();
        String engineer = "";
        if (operator != null && operator.length > 0) {
            engineer = String.join(",", operator);
        }
        fillData.setEngineer(engineer);

        fillData.setInst(stmtContent.getZhuangyuan());
        fillData.setGua(stmtContent.getYayuanren());
        fillData.setDriv(stmtContent.getYuanchejiashi());
        //验收：数组转为字符串
        String[] yanshou = stmtContent.getYanshou();
        String acceptance = "";
        if (yanshou != null && yanshou.length > 0) {
            acceptance = String.join(",", yanshou);
        }
        fillData.setAcceptance(acceptance);
        //其他人员：数组转为字符串
        String[] person = stmtContent.getOtherPerson();
        String other = "";
        if (person != null && person.length > 0) {
            other = String.join(",", person);
        }
        fillData.setOther(other);

        fillData.setRemark(stmtContent.getRemark());
        fillData.setOrderCode(stmtContent.getTaskNumber());
        fillData.setUnitName(stmtContent.getSm_company_mng());
        fillData.setProject(stmtContent.getStatusProject());
        fillData.setDistance(stmtContent.getWangfanlicheng());
        fillData.setStatus(stmtContent.getSm_yuka_mng());
        List<Map<String, Object>> rightList = new ArrayList<>();
        if (voList.size() <= 22) {
            workBook.fill(voList, sheet);
        } else {
            voList.subList(22, voList.size()).forEach(dl -> {
                Map<String, Object> map = new HashMap<>();
                map.put("projectName1", dl.getProjectName());
                map.put("num1", dl.getNum());
                map.put("cljd1", dl.getCljds());
                rightList.add(map);
            });
            workBook.fill(voList.subList(0, 22), sheet);
            workBook.fill(rightList, sheet);

        }
        workBook.fill(fillData, sheet);
        workBook.finish();
        String outputExcelPath = FilePathUtils.getTemplatePath("\\templete\\", "结算单导出.xlsx");
        Workbook workbook = new Workbook();
        //打开指定路径的excel，如果注释掉本行，相当于新建excel
        workbook.loadFromFile(outputExcelPath);

        //获取第一个sheet表格
        Worksheet sheet1 = workbook.getWorksheets().get(0);
        //设置转换后的PDGF页面高宽适应工作表的内容大小
        workbook.getConverterSetting().setSheetFitToPage(true);
        sheet1.saveToPdf(outputPath);
        return minioUtils.uploadFile(getMulFileByPath(outputPath), "test");
    }


    private void common(List<TestListVo> voList, Map<String, Object> itemMap, TestListVo listVo, ModelMngEntity mng, String[] split) {
        if (StringUtils.isNotEmpty(mng.getId())) {
            // listVo.setCljds(itemMap.get(mng.getId()) + "");
            listVo.setCljds(itemMap.get(mng.getId()) != null ? itemMap.get(mng.getId()).toString() : "");
        }
        if (split.length == 2) { // 为2执行
            //曲线条数
            String coverNumber = split[1];
            listVo.setNum(coverNumber);
        } else { // 不为2执行
            //曲点数
            String qudianshu = "";
            listVo.setNum(qudianshu);
        }
        voList.add(listVo);
    }

    /**
     * 导出随钻的pdf
     *
     * @param id
     */
    @Override
    public ObjectItem export(String id) throws Exception {
        //表格对象
        SuiContent suiContent = new SuiContent();
        //根据id获取结算单的内容
        StmtMngEntity stmtMng = this.getById(id);
//        String jsonStr = String.valueOf(JSON.parseObject());
        StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);
        // 获取work数组
        List<WorkDetailVO> workList = JSON.parseArray(stmtContent.getWork(), WorkDetailVO.class);
        //workList中的钻趟数number为自增
        int number = 1;
        for (WorkDetailVO workDetailVO : workList) {
            String cejing = workDetailVO.getCejingDeatil().replaceAll("\\[|\\]|\"", "");
            workDetailVO.setCejingDeatil(workDetailVO.getCejingxiangmu() + " " + cejing);
            workDetailVO.setNumber(number);
            number++;
        }
        //取出待命时间集合
        List<WaitOrderVO> daimingList = JSON.parseArray(stmtContent.getDaiming(), WaitOrderVO.class);
        //daimingList中的index为自增
        int index = 1;
        for (WaitOrderVO waitOrderVO : daimingList) {
            String s = waitOrderVO.getShigongneirong().replaceAll("\\[|\\]|\"", "");
            waitOrderVO.setShigongneirong(s);
            waitOrderVO.setIndex(index);
            index++;
        }
        //取出personwork明细情况集合
        List<RecordDetailVO> recordList = JSON.parseArray(stmtContent.getPersonWork(), RecordDetailVO.class);
        //填充数据
        BeanUtils.copyProperties(stmtContent, suiContent);
        suiContent.setWorkDetailList(recordList);
        suiContent.setWorkList(workList);
        suiContent.setWaitOrderList(daimingList);
        Map<String, Object> object = JSONObject.parseObject(JSONObject.toJSONString(suiContent), Map.class);
        //将map集合放入模板中
        String fileName = "随钻测井施工单2.docx";
        String filePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", fileName);
        XWPFDocument xwpfDocument = WordExportUtil.exportWord07(filePath, object);
        String outFileName = "随钻测井施工单导出2.docx";
        String outFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", outFileName);
        OutputStream outputStream = new FileOutputStream(outFilePath);
        xwpfDocument.write(outputStream);
        outputStream.close();
        String pdfFileName = "随钻测井施工单导出2.pdf";
        String pdfFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", pdfFileName);
        Document doc = new Document(outFilePath);
        doc.save(pdfFilePath, SaveFormat.PDF);
        AsposeUtil.wordToPdf(outFilePath, pdfFilePath);
        return minioUtils.uploadFile(getMulFileByPath(pdfFilePath), "test");
    }

    /**
     * 导出生产测井施工结算单
     */
    @Override
    public ObjectItem exportTestWellSheet(String id) throws Exception {
        //获取文档对象
        LogWorksheet logWorksheet = new LogWorksheet();
        //获取实体对象
        StmtMngEntity stmtMng = this.getById(id);
        //获取content内容
        StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);
        //进行赋值映射
        //名称
        logWorksheet.setTitle(stmtContent.getSm_model_mng());
        //项目部
        logWorksheet.setDep(stmtContent.getProjectDep());
        //队伍
        logWorksheet.setTeam(stmtContent.getDep());
        //任务单号
        logWorksheet.setTaskOrderNumber(stmtContent.getTaskNumber());
        //时间
        logWorksheet.setCurrentTime(simpleDateFormat.format(stmtContent.getCurrentTime()));
        //甲方单位
        logWorksheet.setFirstParty(stmtContent.getSm_company_mng());
        //地区
        logWorksheet.setArea(stmtContent.getSm_area_mng());
        //作业区(舍弃) 井深系数舍弃  目的层舍弃
        //logWorksheet.setWorkZone(stmtContent.get);
        //井号
        logWorksheet.setWellNumber(stmtContent.getJinghao());
        //工作项目
        logWorksheet.setWorkItem(stmtContent.getSm_project_mng());
        //井型
        logWorksheet.setWellType(stmtContent.getSm_jx_mng());
        //井深
        logWorksheet.setWellDepth(stmtContent.getJingshen());
        //套管
        logWorksheet.setDrivepipe(stmtContent.getTaoguanSize());
        //单程公里
        logWorksheet.setOneWayKm(stmtContent.getDanchengongli());
        //放射源类型
        logWorksheet.setRadiateSourceType(stmtContent.getSm_fsy_mng());
        //要求出发时间
        logWorksheet.setAskStartTime(stmtContent.getRequireGoTime());
        //出发时间
        logWorksheet.setStartTime(stmtContent.getGoTime());
        //要求到井时间
        logWorksheet.setAskReachWellTime(stmtContent.getRequireArriveTime());
        //到井时间
        logWorksheet.setReachWellTime(stmtContent.getArriveTime());
        //开工时间
        logWorksheet.setStartWorkTime(stmtContent.getWorkTime());
        //完工时间
        logWorksheet.setFinishWorkTime(stmtContent.getFinishWorkTime());
        //离井时间
        logWorksheet.setLeaveWellTime(stmtContent.getLeaveTime());
        //返队时间
        logWorksheet.setReturnTeamTime(stmtContent.getBackTime());
        //钻井等测井时间
        logWorksheet.setWellTestTime(stmtContent.getZWaitc());
        //测井等钻井时间
        logWorksheet.setWellDrillTime(stmtContent.getCWaitz());
        //测井车号
        logWorksheet.setTestWellNum(stmtContent.getCejingche());

        //送仪器车号
        logWorksheet.setInstrumentCartNum(stmtContent.getSongyiqiche());

        //最高温度
        logWorksheet.setMaxTemperature(stmtContent.getHighTemperature());
        //最低温度
        logWorksheet.setMinTemperature(stmtContent.getLowerTemperature());
        //是否借源
        logWorksheet.setIsRentSource(stmtContent.getJieyuan());
        //成功下井次数/总次数
        logWorksheet.setDescendWellNum(stmtContent.getChenggongbi());

        if (stmtContent.getDuizhang() != null) {
            //队长
            logWorksheet.setTestWellCaptain(String.join(",", stmtContent.getDuizhang()));
        }

        if (stmtContent.getCaozuoyuan() != null) {
            //操作工程师
            logWorksheet.setOperateEngineer(String.join(",", stmtContent.getCaozuoyuan()));
        }

        if (stmtContent.getDuiyuan() != null) {
            //队员
            logWorksheet.setTeamMember(String.join(",", stmtContent.getDuiyuan()));
        }

        //用户评论
        logWorksheet.setUserRemark(stmtContent.getUserAdvice());

        //循环填充  项目名称以及测量井段
        Map map = JSON.parseObject(stmtContent.getProjectItem(), Map.class);
        Set<String> set = map.keySet();

        //计算数据的数量大小
        Integer size = set.size() / 2;
        Integer count = 0;

        List list = new ArrayList();
        List rightList = new ArrayList();

        for (String key : set) {
            count++;
            //通过set的数量多少进行划分左右两边
            ModelMngEntity info = modelMngMapper.findByModelId(key);
            if (info.getName() != null) {
                //存储测量井段
                ProjectDetails projectDetails = new ProjectDetails();
                // 查找 "&&" 的索引位置
                int symbolIndex = info.getName().indexOf("&&");
                if (symbolIndex != -1) {
                    // 提取索引位置之前的子字符串也就是名称
                    String name = info.getName().substring(0, symbolIndex);
                    projectDetails.setProjectName(name);
                    projectDetails.setMeasureWellSection(String.valueOf(map.get(key)));

                    //处理在哪边填充
                    if (count <= size) {
                        //保存到集合中
                        Collections.addAll(rightList, projectDetails);
                        logWorksheet.setRightPro(list);
                    } else {
                        //保存到集合中
                        Collections.addAll(list, projectDetails);
                        logWorksheet.setProject(list);
                    }
                }
            }


        }


        Map<String, Object> object = JSONObject.parseObject(JSONObject.toJSONString(logWorksheet), Map.class);
        //将map集合放入模板中
        String fileName = "生产测井施工结算单.docx";
        String filePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", fileName);
        XWPFDocument xwpfDocument = WordExportUtil.exportWord07(filePath, object);
        String outFileName = "生产测井施工结算单导出.docx";
        String outFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", outFileName);
        OutputStream outputStream = new FileOutputStream(outFilePath);
        xwpfDocument.write(outputStream);
        outputStream.close();
        String pdfFileName = "生产测井施工结算单导出.pdf";
        String pdfFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", pdfFileName);
        Document doc = new Document(outFilePath);
        doc.save(pdfFilePath, SaveFormat.PDF);
        AsposeUtil.wordToPdf(outFilePath, pdfFilePath);
        return minioUtils.uploadFile(getMulFileByPath(pdfFilePath), "test");

    }

    @Override
    public ObjectItem statementExport(List<String> ids, String startTime, String endTime) throws Exception {

        if (CollectionUtils.isEmpty(ids)) {
            List<StmtMngEntity> entityList = list(
                    new LambdaQueryWrapper<StmtMngEntity>()
                            .eq(StmtMngEntity::getStmtName, "测井施工结算单(国产设备)").or().eq(StmtMngEntity::getStmtName, "测井施工结算单(引进设备)"));
            if (CollectionUtils.isEmpty(entityList)) {
                throw new ServiceException("暂无数据，无法导出" + "\uD83D\uDE01");
            }
            ids = entityList.stream().map(StmtMngEntity::getId).collect(Collectors.toList());
        }

        // title
        StatementAllVo allVo = new StatementAllVo();
        UserVo userVo = new UserVo();
        if (StringUtils.isBlank(SecurityUtils.getLoginUser().getUser().getUserName())) {
            userVo.setUser("1");
        } else {
            userVo.setUser(SecurityUtils.getLoginUser().getUser().getUserName());            //表格导出人
        }
        allVo.setCreateTime(simpleDateFormat.format(new Date()));
        allVo.setInterval(startTime + "至" + endTime);
        allVo.setTitle("测井结算单统计表");

        // 数据渲染
        int currentIndex = 1;
        List<StatementVo> voList = new ArrayList<>();
        //获取结算单
        for (String id : ids) {
            StatementVo fillData = new StatementVo();
            fillData.setCurrentIndex(currentIndex++);
            //结算单实体
            StmtMngEntity stmtMng = this.getById(id);
            if (stmtMng != null) {
                fillData.setUploadTime(simpleDateFormat.format(stmtMng.getCreateTime()));
                fillData.setForm(stmtMng.getStmtName());
                // 转换内容
                String jsonStr = String.valueOf(JSON.parseObject(stmtMng.getStmtContent()));
                // 转换结算单实体类
                StmtContent stmtContent = JSON.parseObject(jsonStr, StmtContent.class);
                Map<String, Object> itemMap = new HashMap<>();
                if (stmtContent != null) {
                    if (StringUtils.isNotEmpty(stmtContent.getProjectItem())) {
                        itemMap = JSON.parseObject(stmtContent.getProjectItem(), Map.class);
                    }
                    if (stmtContent.getCaptain() != null) {
                        //小队长
                        String[] team = stmtContent.getCaptain();
                        String captain = "";
                        if (team != null && team.length > 0) {
                            captain = String.join(",", team);
                        }
                        fillData.setLeader(captain);
                    }
                    if (stmtContent.getEngineer() != null) {
                        //操作工程师
                        String[] operator = stmtContent.getEngineer();
                        String engineer = "";
                        if (operator != null && operator.length > 0) {
                            engineer = String.join(",", operator);
                        }
                        fillData.setEngineer(engineer);
                    }
                    if (stmtContent.getYanshou() != null) {
                        //验收
                        String[] yanshou = stmtContent.getYanshou();
                        String acceptance = "";
                        if (yanshou != null && yanshou.length > 0) {
                            acceptance = String.join(",", yanshou);
                        }
                        fillData.setAcceptance(acceptance);
                    }
                    if (stmtContent.getOtherPerson() != null) {
                        //其他人员
                        String[] person = stmtContent.getOtherPerson();
                        String other = "";
                        if (person != null && person.length > 0) {
                            other = String.join(",", person);
                        }
                        fillData.setOther(other);
                    }
                    fillData.setLine(stmtContent.getSm_model_mng());           //系列名称
                    fillData.setDiaochechehao(stmtContent.getDiaocheNumber() + "(" + stmtContent.getDiaocheTon() + ")");    //吊车车号（吨数）
                    fillData.setOrderCode(stmtContent.getTaskNumber());       //任务单号
                    fillData.setAreaName(stmtContent.getSm_area_mng());     //地区
                    fillData.setUnitName(stmtContent.getSm_company_mng());    //甲方单位
                    fillData.setTeamCode(stmtContent.getZuanjingduihao());     //钻井队号
                    fillData.setTeamNum(stmtContent.getJinghao());          //井号
                    fillData.setTeamType(stmtContent.getSm_jx_mng());        // 井型
                    fillData.setWork(stmtContent.getSm_project_mng());      //工作项目
                    fillData.setDeepth(stmtContent.getJingshen());         //井深
                    fillData.setKilo(stmtContent.getDanchengongli());        //单程公里
                    fillData.setAngle(stmtContent.getZuidajingxie());        //最大井斜
                    fillData.setCondition(stmtContent.getSm_jk_mng());        //井况
                    fillData.setRequireGoTime(stmtContent.getRequireGoTime());      //要求出发时间
                    fillData.setArriveTime(stmtContent.getGoTime());        //出发时间
                    fillData.setRequireReach(stmtContent.getRequireArriveTime());      //要求到井时间
                    fillData.setReachTime(stmtContent.getArriveTime());       //到井时间
                    fillData.setWorkTime(stmtContent.getWorkTime());       //开工时间
                    fillData.setFinishWorkTime(stmtContent.getFinishWorkTime());   //完工时间
                    fillData.setLeaveTime(stmtContent.getLeaveTime());        //离井时间
                    fillData.setReturnTime(stmtContent.getBackTime());       //返回时间
                    fillData.setDeliveryNumber(stmtContent.getSongyiqiNumber());     //送仪器车号
                    //todo 吊车往返里程，送仪器车号往返里程，测井车号往返历程，送核磁车号往返里程
                    fillData.setNumber(stmtContent.getCejingNumber());       //测井车号
                    fillData.setOutdoorTem(stmtContent.getHighTemperature());     //室外最高温度
                    fillData.setMinTem(stmtContent.getLowerTemperature());      //室外最低温度
                    fillData.setTime(stmtContent.getCWaitZTime());      //测井等钻井
                    fillData.setTimeTwo(stmtContent.getZWaitCTime());       //钻井等测井
                    fillData.setTool(stmtContent.getShipingjing());        //水平工具
                    fillData.setCon(stmtContent.getHsNongdu());        //井内硫化氢浓度
                    fillData.setDepthH(stmtContent.getShuipingDeep());     //水平段深度
                    fillData.setDepthA(stmtContent.getADeep());      //A点深度
                    fillData.setPressure(stmtContent.getPressure());     //井底压力
                    fillData.setDensity(stmtContent.getDensity());      //泥浆密度
                    fillData.setViscosity(stmtContent.getViscosity());     //泥浆黏度
                    fillData.setTemperature(stmtContent.getJingdiTemperature());    //井底温度
                    fillData.setDelivery(stmtContent.getSm_material_mng());      //资料交处
                    fillData.setBorrowed(stmtContent.getJieyuan());      //是否借源
                    fillData.setDistance(stmtContent.getWangfanlicheng());     //单元格里面的往返里程
                    fillData.setDepartName(stmtContent.getDepName());         //所属项目部
                    fillData.setStatus(stmtContent.getSm_yuka_mng());           //施工状态
                    fillData.setUploader(SecurityUtils.getLoginUser().getUser().getUserName());    //表格上传人
                    fillData.setMriNum(stmtContent.getHeciNumber());
                    fillData.setXiaoTeam(stmtContent.getXiaodui());              //小队名称
                    fillData.setUnit(stmtContent.getMyCompany());
                }

                List<TestListVo> testListVoList = new ArrayList<>();
                List<ModelMngEntity> modelMng = modelMngMapper.findParentId(stmtMng.getModelId());
                for (ModelMngEntity mng : modelMng) {
                    TestListVo vo = new TestListVo();
                    String[] split = mng.getName().split("&&");
                    // 检查项目名称是否为null
                    vo.setProjectName(split[0]);
                    if (itemMap != null) {
                        Object o = itemMap.get(mng.getId());
                        if (o != null) {
                            vo.setCljds(o.toString());
                        }
                    }
                    if (split.length == 2) { // 为2执行
                        //曲线条数
                        String coverNumber = split[1];
                        vo.setNum(coverNumber);
                    } else { // 不为2执行
                        //曲点数
                        vo.setNum("");
                    }
                    testListVoList.add(vo);
                }
                fillData.setVoList(testListVoList);
                voList.add(fillData);
            }
        }
        allVo.setList(voList);
        String fileName = "测井结算单统计表.xlsx";
        //获取模板文件的路径
        String filePath = FilePathUtils.getTemplatePath("\\templete\\detail\\", fileName);
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateUrl(filePath);
        //将表格内容转成map
        Map<String, Object> map = BeanUtil.beanToMap(allVo);
        //将params和map填充到workbook
        org.apache.poi.ss.usermodel.Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        //获取当前时间,格式化
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss");
        String currentTime = formatter.format(LocalDateTime.now());
        String outFileName = "测井结算单统计表导出 " + currentTime + ".xlsx";
        String outPath = FilePathUtils.getTemplatePath("\\templete\\detail\\", outFileName);
        File file = new File(outPath);
        if (!file.exists()) {
            file.createNewFile();// 能创建多级目录
        }
        FileOutputStream fos = new FileOutputStream(outPath);
        workbook.write(fos);
        fos.close();
        return minioUtils.uploadFile(getMulFileByPath(outPath), "test");
    }

    /**
     * 导出桥射联作pdf
     *
     * @param id
     */
    @Override
    public ObjectItem exportQiao(String id) throws Exception {
        //表格内容对象
        QiaoContent qiaoContent = new QiaoContent();
        //根据id获取结算单的stmtContent
        StmtMngEntity stmtMng = this.getById(id);
        String jsonStr = String.valueOf(JSON.parseObject(stmtMng.getStmtContent()));
        StmtContent stmtContent = JSON.parseObject(jsonStr, StmtContent.class);
        //填充数据,将stmtContent数据拷贝到qiaoContent
        BeanUtils.copyProperties(stmtContent, qiaoContent);
        //取出队长，队员和操作员的字符串数组转为字符串，并作处理填充
        String[] cap = stmtContent.getDuizhang();
        String duizhang = "";
        if (cap != null && cap.length > 0) {
            duizhang = String.join(",", duizhang);
        }
        qiaoContent.setDuizhang(duizhang);
        String[] dui = stmtContent.getDuiyuan();
        String duiyuan = "";
        if (dui != null && dui.length > 0) {
            duiyuan = String.join(",", dui);
        }
        qiaoContent.setDuiyuan(duiyuan);
        String[] caozuo = stmtContent.getCaozuoyuan();
        String caozuoyuan = "";
        if (caozuo != null && caozuo.length > 0) {
            caozuoyuan = String.join(",", caozuo);
        }
        qiaoContent.setCaozuoyuan(caozuoyuan);
        //取出stmtcontent的projectItem
        List<QiaoProjectItem> itemList = JSON.parseArray(stmtContent.getProjectItem(), QiaoProjectItem.class);
        List<ProjectItem> projectList = new ArrayList<>();
        ProjectItem projectItem = new ProjectItem();

        if (CollectionUtils.isNotEmpty(itemList)) {
            qiaoContent.setItemList(itemList);
        }
        Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(qiaoContent), Map.class);
        //将map集合放入模板中
        String fileName = "桥射联作施工结算单.docx";
        String filePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", fileName);
        XWPFDocument xwpfDocument = WordExportUtil.exportWord07(filePath, map);
        String outFileName = "桥射联作施工结算单导出.docx";
        String outFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", outFileName);
        OutputStream outputStream = new FileOutputStream(outFilePath);
        xwpfDocument.write(outputStream);
        outputStream.close();
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss");
//        String currentTime = formatter.format(LocalDateTime.now());
//        String pdfFileName = "桥射联作施工结算单导出 " + currentTime + ".pdf";
        String pdfFileName = "桥射联作施工结算单导出.pdf";
        String pdfFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", pdfFileName);
        Document doc = new Document(outFilePath);
        doc.save(pdfFilePath, SaveFormat.PDF);
        AsposeUtil.wordToPdf(outFilePath, pdfFilePath);
        return minioUtils.uploadFile(getMulFileByPath(pdfFilePath), "test");
    }

    /**
     * 导出随钻明细表
     *
     * @param dto
     */
    @Override
    public ObjectItem testSuiExcel(StatementDto dto) throws Exception {

        if (CollectionUtils.isEmpty(dto.getIds())) {
            List<StmtMngEntity> entityList = list(
                    new LambdaQueryWrapper<StmtMngEntity>()
                            .eq(StmtMngEntity::getStmtName, "随钻测井施工结算单"));
            if (CollectionUtils.isEmpty(entityList)) {
                throw new ServiceException("暂无数据，无法导出" + "\uD83D\uDE01");
            }
            dto.setIds(entityList.stream().map(StmtMngEntity::getId).collect(Collectors.toList()));
        }
        //表格全部内容的对象
        SuiExcelAllVO allVO = new SuiExcelAllVO();
        UserVo userVo = new UserVo();
        if (StringUtils.isBlank(SecurityUtils.getLoginUser().getUser().getUserName())) {
            userVo.setUser("1");
        } else {
            userVo.setUser(SecurityUtils.getLoginUser().getUser().getUserName());            //表格导出人
        }
        allVO.setCreateTime(simpleDateFormat.format(new Date()));
        allVO.setInterval(dto.getStartTime() + "至" + dto.getEndTime());
        //序号自增
        int currentIndex = 1;
        //存储表格数据的集合
        List<SuiExcelVO> voList = new ArrayList<>();
        //获取结算单
        for (String id : dto.getIds()) {
            //表格循环部分的对象
            SuiExcelVO excelVO = new SuiExcelVO();
            //填充序号
            excelVO.setCurrentIndex(currentIndex++);
            //结算单实体
            StmtMngEntity stmtMng = this.getById(id);
            if (stmtMng != null) {
                //填充表单,单程公里
                excelVO.setForm(stmtMng.getStmtName());
                if (StringUtils.isNotEmpty(stmtMng.getStmtContent())) {
                    // 转换内容
                    String jsonStr = String.valueOf(JSON.parseObject(stmtMng.getStmtContent()));
                    // 转换结算单实体类
                    StmtContent stmtContent = JSON.parseObject(jsonStr, StmtContent.class);
                    if (stmtContent != null) {
                        //填充其他同级数据
                        BeanUtils.copyProperties(stmtContent, excelVO);
                        //取出work，daiming，personWork集合
                        if (StringUtils.isNotEmpty(stmtContent.getWork())) {
                            List<CeTypeNameVO> nameList = JSON.parseArray(stmtContent.getWork(), CeTypeNameVO.class);
                            if (CollectionUtils.isNotEmpty(nameList)) {
                                AtomicInteger number = new AtomicInteger(1);
                                List<CejingDeatilVO> ceList = new ArrayList<>();
                                nameList.stream().forEach(sl -> {
                                    sl.setNumber(number.get());
                                    number.getAndIncrement();
                                });
                            }
                            excelVO.setDetailList(nameList);
                        }
                        if (StringUtils.isNotEmpty(stmtContent.getPersonWork())) {
                            List<RecordDetailVO> recordList = JSON.parseArray(stmtContent.getPersonWork(), RecordDetailVO.class);
                            excelVO.setRecordList(recordList);
                        }
                        if (StringUtils.isNotEmpty(stmtContent.getDaiming())) {
                            List<WaitOrderVO> waitList = JSON.parseArray(stmtContent.getDaiming(), WaitOrderVO.class);
                            int index = 1;
                            if (CollectionUtils.isNotEmpty(waitList)) {
                                for (WaitOrderVO waitOrderVO : waitList) {
                                    waitOrderVO.setIndex(index);
                                    index++;
                                }
                            }
                            excelVO.setWaitList(waitList);
                        }
                        voList.add(excelVO);
                    }
                }
            }

        }
        allVO.setList(voList);

        String filePath = FilePathUtils.getTemplatePath("\\templete\\detail\\", "随钻施工单统计表.xlsx");
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateUrl(filePath);
        //转map
        Map<String, Object> map = BeanUtil.beanToMap(allVO);
        //将params和map填充到workbook
        org.apache.poi.ss.usermodel.Workbook workbook = ExcelExportUtil.exportExcel(params, map);
//        removeMergedRegions(workbook,0,33,50);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss");
        String currentTime = formatter.format(LocalDateTime.now());
        String outPath = FilePathUtils.getTemplatePath("\\templete\\detail\\", "随钻施工单统计表导出 " + currentTime + ".xlsx");
        FileOutputStream fos = new FileOutputStream(outPath);
        workbook.write(fos);
        fos.close();
        return minioUtils.uploadFile(getMulFileByPath(outPath), "test");
    }

    /**
     * 导出连续油管pdf
     * @param id
     * @throws Exception
     */
    @Override
    public ObjectItem exportTubing(String id) throws Exception {
        //连续油管表格内容对象
        TubingContent tubeContent = new TubingContent();
        StmtMngEntity stmtMng = this.getById(id);
        StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);
        //取出stmtContent里面的projectItem
        Map<String,String> mapList = JSON.parseObject(stmtContent.getProjectItem(), Map.class);
        List<WorkProjectVO> workList = new ArrayList<>();
        //取出key值
        Set<String> set = mapList.keySet();
        for (String s : set) {
            ModelMngEntity entity = modelMngMapper.findByModelId(s);
            if(entity.getName() != null){
                WorkProjectVO workProjectVO = new WorkProjectVO();
                int index = entity.getName().indexOf("&&");
                if(index != -1){
                    String name = entity.getName().substring(0, index);
                    workProjectVO.setProjectItem(name);
                    workProjectVO.setCeliangNum(mapList.get(s));
                    workList.add(workProjectVO);
                    tubeContent.setList(workList);
                }
            }
        }
        //填充数据
        BeanUtils.copyProperties(stmtContent, tubeContent);
        //取出队长，操作员和队员，将字符串数组转为字符串，并填充
        String[] cap = stmtContent.getDuizhang();
        String duizhang = "";
        if (cap != null && cap.length > 0) {
            duizhang = String.join(",", cap);
        }
        tubeContent.setDuizhang(duizhang);
        String[] team = stmtContent.getDuiyuan();
        String duiyuan = "";
        if (team != null && team.length > 0) {
            duiyuan = String.join(",", team);
        }
        tubeContent.setDuiyuan(duiyuan);
        String[] operator = stmtContent.getCaozuoyuan();
        String caozuoyuan = "";
        if (operator != null && operator.length > 0) {
            caozuoyuan = String.join(",", operator);
        }
        tubeContent.setCaozuoyuan(caozuoyuan);

        //将tubeContent转为map
        Map<String, Object> map = JSONObject.parseObject(JSONObject.toJSONString(tubeContent), Map.class);
        //将map集合放入模板中
        String fileName = "连续油管施工结算单.docx";
        String filePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", fileName);
        XWPFDocument xwpfDocument = WordExportUtil.exportWord07(filePath, map);
        String outFileName = "连续油管施工结算单导出.docx";
        String outFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", outFileName);
        FileOutputStream outputStream = new FileOutputStream(outFilePath);
        xwpfDocument.write(outputStream);
        outputStream.close();
        String pdfFileName = "连续油管施工结算单导出.pdf";
        String pdfFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", pdfFileName);
        Document document = new Document(outFilePath);
        document.save(pdfFilePath, SaveFormat.PDF);
        AsposeUtil.wordToPdf(outFilePath, pdfFilePath);
        return minioUtils.uploadFile(getMulFileByPath(pdfFilePath), "test");
    }
    /**
     * 导出射孔施工单pdf
     * @param id
     * @return
     */
    @Override
    public ObjectItem exportBeam(String id) throws Exception {
        //表格的所有内容对象
        BeamContent beamContent = new BeamContent();
        //取出结算单的content
        StmtMngEntity stmtMng = this.getById(id);
        StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);
        //填充数据
        BeanUtils.copyProperties(stmtContent, beamContent);
        //取出stmtContent中的projectItem
        List<ProjectItem> projectItemList = JSON.parseArray(stmtContent.getProjectItem(), ProjectItem.class);
        log.info("****projectItemList的值{}",projectItemList);
        //初始化序号
        int number = 1;
        ProjectItem projectItem = new ProjectItem();
        if (CollectionUtils.isNotEmpty(projectItemList)) {
            //todo wellList和houduList没有值
            for (ProjectItem item : projectItemList) {
//                item.setNumber(String.valueOf(number ++));
                item.setNumber(number ++);
            }
//            projectItem.setNumber(String.valueOf(number));
            projectItem.setNumber(number);
            beamContent.setList(projectItemList);
        }
        //取出队长，操作员和队员，将字符串数组转为字符串，并填充
        String[] cap = stmtContent.getDuizhang();
        String duizhang = "";
        if (cap != null && cap.length > 0) {
            duizhang = String.join(",", cap);
        }
        beamContent.setDuizhang(duizhang);
        String[] team = stmtContent.getDuiyuan();
        String duiyuan = "";
        if (team != null && team.length > 0) {
            duiyuan = String.join(",", team);
        }
        beamContent.setDuiyuan(duiyuan);
        String[] operator = stmtContent.getCaozuoyuan();
        String caozuoyuan = "";
        if (operator != null && operator.length > 0) {
            caozuoyuan = String.join(",", operator);
        }
        beamContent.setCaozuoyuan(caozuoyuan);
        //转map
        Map<String,Object> map = JSONObject.parseObject(JSONObject.toJSONString(beamContent), Map.class);
        log.info(">>>>>>{}",map);
        String fileName = "射孔施工结算单.docx";
        String filePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", fileName);
        XWPFDocument xwpfDocument = WordExportUtil.exportWord07(filePath, map);
        String outFileName = "射孔施工结算单导出.docx";
        String outFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", outFileName);
        FileOutputStream outputStream = new FileOutputStream(outFilePath);
        xwpfDocument.write(outputStream);
        outputStream.close();
        String pdfFileName = "射孔施工结算单导出.pdf";
        String pdfFilePath = FilePathUtils.getTemplatePath("\\templete\\exportdoc\\", pdfFileName);
        Document document = new Document(outFilePath);
        document.save(pdfFilePath, SaveFormat.PDF);
        AsposeUtil.wordToPdf(outFilePath, pdfFilePath);
        return minioUtils.uploadFile(getMulFileByPath(pdfFilePath), "test");
    }

    /**
     * 射孔单井施工单
     */
    @Override
    public ObjectItem exportShe(List<String> ids, String startTime, String endTime) throws Exception {
        if (CollectionUtils.isEmpty(ids)) {
            List<StmtMngEntity> entityList = list(
                    new LambdaQueryWrapper<StmtMngEntity>()
                            .eq(StmtMngEntity::getStmtName, "射孔单井施工结算单").eq(StmtMngEntity::getStatus, 1));
            if (CollectionUtils.isEmpty(entityList)) {
                throw new ServiceException("暂无数据，无法导出" + "\uD83D\uDE01");
            }
            ids = entityList.stream().map(StmtMngEntity::getId).collect(Collectors.toList());
        }
        //表格全部内容的对象
        GunExcelAllContent allContent = new GunExcelAllContent();
        //填充表格导出人，导出时间，区间
//        allContent.setUser(SecurityUtils.getLoginUser().getSysUser().getUserName());
        allContent.setCreateTime(simpleDateFormat.format(new Date()));
        allContent.setInterval(startTime + "至" + endTime);
        //定义序号
        int currentIndex = 1;
        //定义一个集合存储表格数据
        List<GunExcelVO> gunList = new ArrayList<>();
        //获取结算单
        for (String id : ids) {
            //表格循环部分的对象
            GunExcelVO excelVO = new GunExcelVO();
            //填充序号
            excelVO.setCurrentIndex(currentIndex++);
            StmtMngEntity stmtMng = this.getById(id);
            StmtContent stmtContent = JSON.parseObject(JSON.parse(stmtMng.getStmtContent()).toString(), StmtContent.class);
            //填充井段部分的内容
            int number = 1;
            List<ProjectItem> itemList = JSON.parseArray(stmtContent.getProjectItem(), ProjectItem.class);
            List<ProjectItem> projectItemList = new ArrayList<>();
            for (ProjectItem item : itemList) {
                ProjectItem projectItem = new ProjectItem();
                projectItem.setNumber(number);
                projectItem.setYoudi(item.getYoudi());
                projectItem.setYouding(item.getYouding());
                projectItem.setKongmi(item.getKongmi());
                projectItemList.add(projectItem);
                number ++;
            }
            excelVO.setExcelList(projectItemList);
            //填充厚度
            List<ProjectItemJcHoudu> houduList = JSON.parseArray(stmtContent.getProjectItemJcHoudu(), ProjectItemJcHoudu.class);
            List<ProjectItemJcHoudu> list = new ArrayList<>();
            for (ProjectItemJcHoudu itemJcHoudu : houduList) {
                ProjectItemJcHoudu houdu = new ProjectItemJcHoudu();
                houdu.setJiacenghoudu(itemJcHoudu.getJiacenghoudu());
                list.add(houdu);
            }
            excelVO.setHouduList(list);
            //填充同级数据
            BeanUtils.copyProperties(stmtContent, excelVO);
            //填充表单名称
            excelVO.setForm(stmtMng.getStmtName());
            gunList.add(excelVO);
            //取出队长，操作员和队员，将字符串数组转为字符串，并填充
            String[] cap = stmtContent.getDuizhang();
            String duizhang = "";
            if (cap != null && cap.length > 0) {
                duizhang = String.join(",", cap);
            }
            excelVO.setDuizhang(duizhang);
            String[] team = stmtContent.getDuiyuan();
            String duiyuan = "";
            if (team != null && team.length > 0) {
                duiyuan = String.join(",", team);
            }
            excelVO.setDuiyuan(duiyuan);
            String[] operator = stmtContent.getCaozuoyuan();
            String caozuoyuan = "";
            if (operator != null && operator.length > 0) {
                caozuoyuan = String.join(",", operator);
            }
            excelVO.setCaozuoyuan(caozuoyuan);
        }
        //填充到表格里面
        allContent.setList(gunList);
        String filePath = FilePathUtils.getTemplatePath("\\templete\\detail\\", "射孔单井施工单统计表.xlsx");
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateUrl(filePath);
        //转map
        Map<String, Object> map = BeanUtil.beanToMap(allContent);
        //将params和map填充到workbook
        org.apache.poi.ss.usermodel.Workbook workbook = ExcelExportUtil.exportExcel(params, map);
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH_mm_ss");
//        String currentTime = formatter.format(LocalDateTime.now());
        String outPath = FilePathUtils.getTemplatePath("\\templete\\detail\\", "射孔单井施工单统计表导出.xlsx");
        FileOutputStream fos = new FileOutputStream(outPath);
        workbook.write(fos);
        fos.close();
        return minioUtils.uploadFile(getMulFileByPath(outPath), "test");
    }


    //本地文件转为MultipartFile类型(文件路径)
    public static MultipartFile getMulFileByPath(String picPath) {
        Path path = Paths.get(picPath);
        FileItem fileItem = createFileItem(picPath);
        try {
            return new MockMultipartFile(path.getFileName().toString(), path.getFileName().toString(),Files.probeContentType(path),Files.readAllBytes(path));
        }catch (Exception e){
            throw new ServiceException(e.getMessage());
        }
    }

    private static FileItem createFileItem(String filePath) {
        FileItemFactory factory = new DiskFileItemFactory(16, null);
        String textFieldName = "textField";
        int num = filePath.lastIndexOf(".");
        String extFile = filePath.substring(num);
        FileItem item = factory.createItem(textFieldName, "text/plain", true, UUID.randomUUID() + extFile);
        File newfile = new File(filePath);
        long fileSize = newfile.length();
        int bytesRead = 0;
        byte[] buffer = new byte[(int) fileSize];
        try {
            FileInputStream fis = new FileInputStream(newfile);
            OutputStream os = item.getOutputStream();
            while ((bytesRead = fis.read(buffer, 0, buffer.length)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            os.close();
            fis.close();
        } catch (IOException e) {
            log.info("***********{}", e.getMessage());
        }
        return item;
    }


    /**
     * 导出桥射施工表单
     */
    @Override
    public ObjectItem exportBridgeShootSheet(List<String> ids, String startTime, String endTime) throws Exception {


        if (CollectionUtils.isEmpty(ids)) {
            List<StmtMngEntity> entityList = list(
                    new LambdaQueryWrapper<StmtMngEntity>()
                            .eq(StmtMngEntity::getStmtName, "桥射联作单井施工结算单").eq(StmtMngEntity::getStatus, 1));
            if (CollectionUtils.isEmpty(entityList)) {
                throw new ServiceException("暂无数据，无法导出" + "\uD83D\uDE01");
            }
            ids = entityList.stream().map(StmtMngEntity::getId).collect(Collectors.toList());
        }
        //实例化
        BridgeFire bridgeFire = new BridgeFire();
        UserVo userVo = new UserVo();
        //获取表格导出人
        if (StringUtils.isBlank(SecurityUtils.getLoginUser().getUser().getUserName())) {
            userVo.setUser("1");
        } else {
            userVo.setUser(SecurityUtils.getLoginUser().getUser().getUserName());
        }
        //表格导出时间区间
        bridgeFire.setCreateTime(simpleDateFormat.format(new Date()));
        bridgeFire.setInterval(startTime + "至" + endTime);
        bridgeFire.setTitle("桥射联作施工单统计表");


        // 数据渲染
        int currentIndex = 1;
        List<QiaoContent> voList = new ArrayList<>();


        //施工单处理
        for (String id : ids) {
            QiaoContent fillData = new QiaoContent();
            fillData.setCurrentIndex(currentIndex++); //序号
            List<BuildersInfo> list = new ArrayList<>();
            //结算单实体
            StmtMngEntity stmtMng = this.getById(id);


            if (stmtMng != null) {
                if (StringUtils.isNotEmpty(stmtMng.getStmtContent())) {
                    // 转换结算单实体类,获取整个JSON格式的字符串数据
                    StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);

                    //上传人 , 对应的是createBy
                    fillData.setUplink(stmtMng.getCreateBy());
                    //上传时间 , 对应的是 uploadTime字段值
                    if (stmtMng.getUploadTime() != null) {
                        fillData.setCurrentTime(simpleDateFormat.format(stmtMng.getUploadTime()));
                    }


                    if (stmtContent != null) {
                        // map 装载item
                        //获取json字符串中的projectITem对象
                        if (stmtContent.getProjectItem() != null) {

                            List<QiaoProjectItem> projectItem = JSON.parseArray(stmtContent.getProjectItem(), QiaoProjectItem.class);
                            for (int i = 0; i < projectItem.size(); i++) {
                                QiaoProjectItem item = projectItem.get(i);
                                //段序
                                fillData.setDuanxuan(String.valueOf(item.getDuanxuan()));
                                //桥塞类别
                                fillData.setQiaosaiType(String.valueOf(item.getQiaosaiType()));
                                //获取proDetailItem
                                // TODO: 2023/11/22
                                List<ProDetailItem> proDetailItem = item.getProDetailItem();
                                if (proDetailItem.size() != 0) {

                                    ProDetailItem proDetail = proDetailItem.get(0);

                                    if (proDetail != null) {

                                        //簇序
                                        fillData.setCuxu(proDetail.getCuxu());

                                        //井段
                                        WellSection wellSection = new WellSection();
                                        wellSection.setYouDi(proDetail.getYouDi());
                                        wellSection.setYouDing(proDetail.getYouDing());
                                        List list1 = new ArrayList();
                                        list1.add(wellSection);
                                        fillData.setJingduan(list1);
                                        fillData.setQiangxing(proDetail.getQiangxing());
                                        fillData.setQiangshu(proDetail.getQiangshu());
                                        fillData.setDanxing(proDetail.getDanxing());
                                        fillData.setHoudu(proDetail.getHoudu());
                                        fillData.setDanshu(proDetail.getDanshu());


                                    }
                                }

                                //获取统计
                                Total total = item.getTotal();
                                fillData.setGunCount(String.valueOf(total.getQiangzhi()));
                                fillData.setTotalPly(String.valueOf(total.getHoudu()));
                                fillData.setBulletHole(String.valueOf(total.getDankong()));


                            }
                        }
                        //将后台字段中的字段绑定到当前对象中
                        //任务单号
                        fillData.setTaskNumber(stmtContent.getTaskNumber());
                        //表单名称
                        fillData.setFormName("桥射联作施工统计表");
                        //施工类型
                        fillData.setBuildType("桥射联作");
                        //所属单位
                        fillData.setAffiliatedUnit("中油测井新疆分公司");


                        //所属项目部
                        fillData.setProjectDep(stmtContent.getProjectDep());
                        //所属小队
                        fillData.setDep(stmtContent.getDep());


                        //地区
                        fillData.setSm_area_mng(stmtContent.getSm_area_mng());
                        //甲方单位
                        fillData.setSm_company_mng(stmtContent.getSm_company_mng());
                        //井号
                        fillData.setJinghao(stmtContent.getJinghao());
                        //井别
                        fillData.setJingbie(stmtContent.getJingbie());
                        //井型
                        fillData.setSm_jx_mng(stmtContent.getSm_jx_mng());
                        //井况
                        fillData.setSm_jk_mng(stmtContent.getSm_jk_mng());
                        //井深
                        fillData.setJingshen(stmtContent.getJingshen());
                        //套管尺寸
                        fillData.setTaoguanSize(stmtContent.getTaoguanSize());
                        //井内液体
                        fillData.setJingneiyeti(stmtContent.getJingneiyeti());
                        //单程公里
                        fillData.setDanchengongli(stmtContent.getDanchengongli());
                        //要求出发时间
                        fillData.setRequireGoTime(stmtContent.getRequireGoTime());
                        //出发时间
                        fillData.setGoTime(stmtContent.getGoTime());
                        //要求到井时间
                        fillData.setRequireArriveTime(stmtContent.getRequireArriveTime());
                        //到井时间
                        fillData.setArriveTime(stmtContent.getArriveTime());
                        //开工时间
                        fillData.setWorkTime(stmtContent.getWorkTime());
                        //完工时间
                        fillData.setFinishWorkTime(stmtContent.getFinishWorkTime());
                        //离井时间
                        fillData.setLeaveTime(stmtContent.getLeaveTime());
                        //返回时间
                        fillData.setBackTime(stmtContent.getBackTime());
                        //送仪器车
                        fillData.setYiqiche(stmtContent.getYiqiche());
                        //往返里程
                        fillData.setRoundTripMileage(stmtContent.getWangfanlicheng());
                        //送炮车号
                        fillData.setSongpaoChe(stmtContent.getSongpaoChe());
                        //吊车天数
                        fillData.setDiaocheDays(stmtContent.getDiaocheDays());
                        //泵车天数
                        fillData.setBengcheDays(stmtContent.getBengcheDays());
                        //最大井斜
                        fillData.setZuidajingxie(stmtContent.getZuidajingxie());
                        //射孔等井队时间
                        fillData.setSWaitJ(stmtContent.getSWaitJ());
                        //井队等射孔时间
                        fillData.setJWaits(stmtContent.getJWaits());
                        //成功下井次数/总次数
                        fillData.setChenggongbi(stmtContent.getChenggongbi());
                        //室外最高气温
                        fillData.setHighTemperature(stmtContent.getHighTemperature());
                        //室外最低温度
                        fillData.setLowerTemperature(stmtContent.getLowerTemperature());
                        //井内硫化氢浓度
                        fillData.setHsNongdu(stmtContent.getHsNongdu());
                        //总段数
                        fillData.setTotalDuanshu(stmtContent.getTotalDuanshu());
                        //总簇数
                        fillData.setTotalCushu(stmtContent.getTotalCushu());
                        //总孔数
                        fillData.setTotalKongshu(stmtContent.getTotalKongshu());
                        //命中率
                        fillData.setMingzhongRate(stmtContent.getMingzhongRate());
                        //发射率
                        fillData.setFasheRate(stmtContent.getFasheRate());
                        //可溶桥塞个数
                        fillData.setKerongsai(stmtContent.getKerongsai());
                        //速钻桥塞个数
                        fillData.setSuzuanqiaosai(stmtContent.getSuzuanqiaosai());


                        // TODO: 2023/11/21 施工人员情况
                        BuildersInfo buildersInfo = new BuildersInfo();
                        if (stmtContent.getDuizhang() != null) {
                            buildersInfo.setDuizhang(String.join(",", stmtContent.getDuizhang()));
                        }
                        if (stmtContent.getDuiyuan() != null) {
                            buildersInfo.setDuiyuan(String.join(",", stmtContent.getDuiyuan()));
                        }
                        if (stmtContent.getCaozuoyuan() != null) {
                            buildersInfo.setCaozuoyuan(String.join(",", stmtContent.getCaozuoyuan()));
                        }


                        list.add(buildersInfo);
                        fillData.setBuildersInfos(list);
                        voList.add(fillData);
                    }
                }
            }
        }
        bridgeFire.setList(voList);


        String fileName = "桥射联作施工单统计表.xlsx";
        //获取模板文件的路径
        String filePath = FilePathUtils.getTemplatePath("\\templete\\qiaoshedocx\\", fileName);
//        String filePath = "src/main/resources/templete/qiaoshedocx/桥射联作施工统计表.xlsx";
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateUrl(filePath);
        //将表格内容转成map
        Map<String, Object> map = BeanUtil.beanToMap(bridgeFire);
        //将params和map填充到workbook
        org.apache.poi.ss.usermodel.Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        String outFileName = "桥射联作施工单统计表导出.xlsx";
        // String outPath = FilePathUtils.getTemplatePath("\\templete\\qiaoshedocx\\", outFileName);
        String outPath = "templete/qiaoshedocx" + outFileName;

        File file = new File(outPath);
        if (!file.exists()) {
            file.createNewFile();// 能创建多级目录
        }


        FileOutputStream fos = new FileOutputStream(outPath);
        workbook.write(fos);
        fos.close();
        return minioUtils.uploadFile(getMulFileByPath(outPath), "test");
    }


    /**
     * 导出生产测井施工单统计表
     */
    @Override
    public ObjectItem exportTestWellExcel(List<String> ids, String startTime, String endTime) throws Exception {
        if (CollectionUtils.isEmpty(ids)) {
            List<StmtMngEntity> entityList = list(
                    new LambdaQueryWrapper<StmtMngEntity>()
                            .eq(StmtMngEntity::getStmtName, "生产测井施工单统计表").eq(StmtMngEntity::getStatus, 1));
            if (CollectionUtils.isEmpty(entityList)) {
                throw new ServiceException("暂无数据，无法导出" + "\uD83D\uDE01");
            }
            ids = entityList.stream().map(StmtMngEntity::getId).collect(Collectors.toList());
        }


        //实例化
        LogWorkExcel logWorkExcel = new LogWorkExcel();

        //获取表格导出人
//        if (StringUtils.isBlank(SecurityUtils.getLoginUser().getSysUser().getUserName())) {
//            logWorkExcel.setUser("1");
//        } else {
//            logWorkExcel.setUser(SecurityUtils.getLoginUser().getSysUser().getUserName());
//        }

        //表格导出时间区间
        logWorkExcel.setCreateTime(simpleDateFormat.format(new Date()));
        logWorkExcel.setInterval(startTime + "至" + endTime);
        logWorkExcel.setTitle("生产测井施工单统计表");

        // 数据渲染
        int currentIndex = 1;
        List<LogWorksheet> voList = new ArrayList<>();
        for (String id : ids) {
            LogWorksheet fillData = new LogWorksheet();
            fillData.setCurrentIndex(currentIndex++); //序号
            List<BuildersInfo> list = new ArrayList<>();
            //结算单实体
            StmtMngEntity stmtMng = this.getById(id);
            if (stmtMng.getStmtName() !=null ) {
                //表单名称
                fillData.setFormName(stmtMng.getStmtName());
            }

            if (stmtMng != null) {
                if (StringUtils.isNotEmpty(stmtMng.getStmtContent())) {
                    // 转换结算单实体类,获取整个JSON格式的字符串数据
                    StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);

                    //上传人 , 对应的是createBy
                    fillData.setUplink(stmtMng.getCreateBy());
                    //上传时间 , 对应的是 uploadTime字段值
                    if (stmtMng.getUploadTime() != null) {
                        fillData.setUploadTime(simpleDateFormat.format(stmtMng.getUploadTime()));
                    }


                    if (stmtContent != null) {
                        // map 装载item
                        //所属项目部
                        fillData.setDep(stmtContent.getDep());
                        //所属单位
                        fillData.setUnit("中油测井新疆分公司");
                        //队伍
                        fillData.setTeam(stmtContent.getDep());
                        //任务单号
                        fillData.setTaskOrderNumber(stmtContent.getTaskNumber());
                        //时间
                        fillData.setCurrentTime(simpleDateFormat.format(stmtContent.getCurrentTime()));
                        //甲方单位
                        fillData.setFirstParty(stmtContent.getSm_company_mng());
                        //地区
                        fillData.setArea(stmtContent.getSm_area_mng());
                        //作业区(舍弃) 井深系数舍弃  目的层舍弃
                        //logWorksheet.setWorkZone(stmtContent.get);
                        //井号
                        fillData.setWellNumber(stmtContent.getJinghao());
                        //工作项目
                        fillData.setWorkItem(stmtContent.getSm_project_mng());
                        //井型
                        fillData.setWellType(stmtContent.getSm_jx_mng());
                        //井深
                        fillData.setWellDepth(stmtContent.getJingshen());
                        //套管
                        fillData.setDrivepipe(stmtContent.getTaoguanSize());
                        //单程公里
                        fillData.setOneWayKm(stmtContent.getDanchengongli());
                        //放射源类型
                        fillData.setRadiateSourceType(stmtContent.getSm_fsy_mng());
                        //要求出发时间
                        fillData.setAskStartTime(stmtContent.getRequireGoTime());
                        //出发时间
                        fillData.setStartTime(stmtContent.getGoTime());
                        //要求到井时间
                        fillData.setAskReachWellTime(stmtContent.getRequireArriveTime());
                        //到井时间
                        fillData.setReachWellTime(stmtContent.getArriveTime());
                        //开工时间
                        fillData.setStartWorkTime(stmtContent.getWorkTime());
                        //完工时间
                        fillData.setFinishWorkTime(stmtContent.getFinishWorkTime());
                        //离井时间
                        fillData.setLeaveWellTime(stmtContent.getLeaveTime());
                        //返队时间
                        fillData.setReturnTeamTime(stmtContent.getBackTime());
                        //钻井等测井时间
                        fillData.setWellTestTime(stmtContent.getZWaitc());
                        //测井等钻井时间
                        fillData.setWellDrillTime(stmtContent.getCWaitz());
                        //测井车号
                        fillData.setTestWellNum(stmtContent.getCejingche());

                        //送仪器车号
                        fillData.setInstrumentCartNum(stmtContent.getSongyiqiche());

                        //最高温度
                        fillData.setMaxTemperature(stmtContent.getHighTemperature());
                        //最低温度
                        fillData.setMinTemperature(stmtContent.getLowerTemperature());
                        //是否借源
                        fillData.setIsRentSource(stmtContent.getJieyuan());
                        //成功下井次数/总次数
                        fillData.setDescendWellNum(stmtContent.getChenggongbi());

                        //用户评论
                        fillData.setUserRemark(stmtContent.getUserAdvice());


                        // TODO: 2023/11/29  施工人员情况
                        if(stmtContent.getDuizhang() != null){
                            //队长
                            fillData.setTestWellCaptain(String.join(",", stmtContent.getDuizhang()));
                        }
                        if(stmtContent.getDuiyuan() != null){
                            //队员
                            fillData.setTeamMember(String.join(",", stmtContent.getDuiyuan()));
                        }
                        if(stmtContent.getCaozuoyuan() != null){
                            //操作员
                            fillData.setOperateEngineer(String.join(",", stmtContent.getCaozuoyuan()));
                        }
                        voList.add(fillData);
                    }
                }
            }
        }
        String fileName = "生产测井施工单统计表.xlsx";
        //获取模板文件的路径
        String filePath = FilePathUtils.getTemplatePath("\\templete\\detail\\", fileName);
//        String filePath = "src/main/resources/templete/qiaoshedocx/桥射联作施工统计表.xlsx";
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateUrl(filePath);
        //将表格内容转成map
        Map<String, Object> map = BeanUtil.beanToMap(logWorkExcel);
        //将params和map填充到workbook
        org.apache.poi.ss.usermodel.Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        String outFileName = "生产测井施工单统计表.xlsx"+new Date();
        String outPath = FilePathUtils.getTemplatePath("\\templete\\detail\\", outFileName);

        File file = new File(outPath);
        if (!file.exists()) {
            file.createNewFile();// 能创建多级目录
        }

        FileOutputStream fos = new FileOutputStream(outPath);
        workbook.write(fos);
        fos.close();
        return minioUtils.uploadFile(getMulFileByPath(outPath), "test");
    }


    /**
     * 导出连续油管单井施工单
     */
    @Override
    public ObjectItem exportCoiledTubeExcel(List<String> ids, String startTime, String endTime) throws Exception {
        if (CollectionUtils.isEmpty(ids)) {
            List<StmtMngEntity> entityList = list(
                    new LambdaQueryWrapper<StmtMngEntity>()
                            .eq(StmtMngEntity::getStmtName, "连续油管单井施工单统计表").eq(StmtMngEntity::getStatus, 1));
            if (CollectionUtils.isEmpty(entityList)) {
                throw new ServiceException("暂无数据，无法导出" + "\uD83D\uDE01");
            }
            ids = entityList.stream().map(StmtMngEntity::getId).collect(Collectors.toList());
        }
        CoiledTubeExcel excel = new CoiledTubeExcel();

        //获取表格导出人
        if (StringUtils.isBlank(SecurityUtils.getLoginUser().getUser().getUserName())) {
            excel.setUser("1");
        } else {
            excel.setUser(SecurityUtils.getLoginUser().getUser().getUserName());
        }
        //表格导出时间区间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        excel.setCreateTime(sdf.format(new Date()));
        excel.setInterval(startTime + "至" + endTime);
        excel.setTitle("连续油管单井施工单统计表");

        // 数据渲染
        int currentIndex = 1;
        List<TubingContent> voList = new ArrayList<>();
        for (String id : ids) {
            TubingContent fillData = new TubingContent();
            fillData.setCurrentIndex(currentIndex++); //序号
            List<WorkProjectVO> list = new ArrayList<>();
            //结算单实体
            StmtMngEntity stmtMng = this.getById(id);
            if (stmtMng.getStmtName() != null) {
                //表单名称
                fillData.setFormName(stmtMng.getStmtName());
            }
            if (stmtMng != null) {
                if (StringUtils.isNotEmpty(stmtMng.getStmtContent())) {
                    // 转换结算单实体类,获取整个JSON格式的字符串数据
                    StmtContent stmtContent = JSON.parseObject(stmtMng.getStmtContent(), StmtContent.class);
                    //上传人 , 对应的是createBy
                    fillData.setUplink(stmtMng.getCreateBy());
                    //上传时间 , 对应的是 uploadTime字段值
                    fillData.setUploadTime(sdf.format(stmtContent.getCurrentTime()));
                    if (stmtContent != null) {
                        //任务单号
                        fillData.setTaskOrderNum(stmtContent.getTaskNumber());
                        //所属单位
                        fillData.setUnit("中油测井新疆分公司");
                        //所属项目部
                        fillData.setDep(stmtContent.getDep());
                        //所属小队
                        fillData.setTeam(stmtContent.getDep());
                        //地区
                        fillData.setArea(stmtContent.getSm_area_mng());
                        //甲方单位
                        fillData.setFirstParty(stmtContent.getSm_company_mng());
                        //井号
                        fillData.setWellNum(stmtContent.getJinghao());
                        //井别
                        fillData.setWellBetSu(stmtContent.getSm_jb_mng());
                        //井型
                        fillData.setWellType(stmtContent.getSm_jx_mng());
                        //井况
                        fillData.setSm_jk_mng(stmtContent.getSm_jk_mng());
                        //井深
                        fillData.setWellDepth(stmtContent.getJingshen());
                        //作业制度数
                        fillData.setZhidushu(stmtContent.getZhidushu());
                        //井内液体
                        fillData.setSm_jnyt_mng(stmtContent.getSm_jnyt_mng());
                        //单程公里
                        fillData.setDanchengongli(stmtContent.getDanchengongli());
                        //运输里程
                        fillData.setYunshugongli(stmtContent.getYunshugongli());
                        //吊车号
                        fillData.setDiaoche(stmtContent.getDiaoche());
                        //往返里程
                        fillData.setWangfanlicheng(stmtContent.getWangfanlicheng());
                        //连续油管设备
                        fillData.setShebei(stmtContent.getShebei());
                        //开始井深
                        fillData.setStartDeep(stmtContent.getStartDeep());
                        //结束井深
                        fillData.setEndDeep(stmtContent.getEndDeep());
                        //要求出发时间
                        fillData.setRequireGoTime(stmtContent.getRequireGoTime());
                        //出发时间
                        fillData.setGoTime(stmtContent.getGoTime());
                        //要求到井时间
                        fillData.setRequireArriveTime(stmtContent.getRequireArriveTime());
                        //到井时间
                        fillData.setArriveTime(stmtContent.getArriveTime());
                        //开工时间
                        fillData.setWorkTime(stmtContent.getWorkTime());
                        //完工时间
                        fillData.setFinishWorkTime(stmtContent.getFinishWorkTime());
                        //离井时间
                        fillData.setLeaveTime(stmtContent.getLeaveTime());
                        //返回时间
                        fillData.setBackTime(stmtContent.getBackTime());
                        //最大井斜
                        fillData.setXiedu(stmtContent.getXiedu());
                        //钻井等测井时间
                        fillData.setZWaitc(stmtContent.getZWaitc());
                        //测井等钻井时间
                        fillData.setCWaitz(stmtContent.getCWaitz());
                        //成功下井次数/总次数，将数据处理成 123/321 这种样式
                        String string = stmtContent.getChenggongbi();
                        String[] s = string.substring(string.indexOf("[")+1, string.lastIndexOf("]")).split(",");
                        String str = converterUtils.DataFormatConverter(s);
                        fillData.setChenggongbi(str);
                        //最高温度
                        fillData.setHighTemperature(stmtContent.getHighTemperature());
                        //最低温度
                        fillData.setLowerTemperature(stmtContent.getLowerTemperature());
                        //硫化氢浓度
                        fillData.setNongdu(stmtContent.getNongdu());
                        //项目名称
                        List<WorkProjectVO> workList = new ArrayList<>();
                        Map map = JSON.parseObject(stmtContent.getProjectItem(), Map.class);
                        Set<String> set = map.keySet();
                        for (String key : set) {
                            //通过set的数量多少进行划分左右两边
                            ModelMngEntity info = modelMngMapper.findByModelId(key);
                            if (info.getName() != null) {
                                //存储作业项目
                                WorkProjectVO workProject = new WorkProjectVO();
                                // 查找 "&&" 的索引位置
                                int symbolIndex = info.getName().indexOf("&&");
                                if (symbolIndex != -1) {
                                    // 提取索引位置之前的子字符串也就是名称
                                    String name = info.getName().substring(0, symbolIndex);
                                    workProject.setProjectItem(name);
                                    workProject.setCeliangNum(String.valueOf(map.get(key)));
                                    //保存到集合中
                                    Collections.addAll(workList, workProject);
                                    fillData.setList(workList);
                                }
                            }
                        }
                        //fillData.setList();
                        //循环填充  项目名称以及测量井段
                        // TODO: 2023/11/29  施工人员情况
                        if (stmtContent.getDuizhang() != null) {
                            //队长
                            fillData.setTeamHeader(String.join(",", stmtContent.getDuizhang()));
                        }
                        if (stmtContent.getDuiyuan() != null) {
                            //队员
                            fillData.setTeamMember(String.join(",", stmtContent.getDuiyuan()));
                        }
                        if (stmtContent.getCaozuoyuan() != null) {
                            //操作员
                            fillData.setOperate(String.join(",", stmtContent.getCaozuoyuan()));
                        }
                        voList.add(fillData);
                    }
                }
            }
        }
        excel.setList(voList);

        String fileName = "连续油管单井施工单统计表.xlsx";
        //获取模板文件的路径
        String filePath = FilePathUtils.getTemplatePath("\\templete\\detail\\", fileName);
        //获取模板文件的路径
//        String filePath = "templete/qiaoshedocx/连续油管单井施工单统计表 .xlsx";
        TemplateExportParams params = new TemplateExportParams();
        params.setTemplateUrl(filePath);
        //将表格内容转成map
        Map<String, Object> map = BeanUtil.beanToMap(excel);
        //将params和map填充到workbook
        org.apache.poi.ss.usermodel.Workbook workbook = ExcelExportUtil.exportExcel(params, map);
        //String outFileName = "连续油管单井施工单统计表导出.xlsx"+simpleDateFormat.format(new Date());
        String outFileName = "连续油管单井施工单统计表.xlsx";
        String outPath = FilePathUtils.getTemplatePath("\\templete\\detail\\", outFileName);
//        String outPath = "templete/excel" + outFileName;

        File file = new File(outPath);
        if (!file.exists()) {
            file.getParentFile().mkdir();
            file.createNewFile();// 能创建多级目录
        }

        FileOutputStream fos = new FileOutputStream(outPath);
        workbook.write(fos);
        fos.close();
        return minioUtils.uploadFile(getMulFileByPath(outPath), "test");
    }
}









